<?php
if (! defined('IN_WEB')) {
    exit('Access Denied');
}

$ctrl = trim($_GET['ctrl']) ? trim($_GET['ctrl']) : 'index';
$act = trim($_GET['act']) ? trim($_GET['act']) : 'index';

//分析路径，引入控制层
$ctrlClassName = _to_lower_and_ucfirst($ctrl)."Controller";

$pinfo = pathinfo($_SERVER['PHP_SELF']);

$ctrlFolder = $pinfo['filename'];
$ctrlFileName = ROOT . "/controller/{$ctrlFolder}/{$ctrlClassName}.class.php";

require_once ($ctrlFileName);
$Controller = new $ctrlClassName();

//权限判断
$UserAction = new UserAction();
$adminLogin = $UserAction->hasPurview($ctrlFolder, $ctrl, $act);


if (method_exists($Controller, $act)) {
    $Controller->$act();
} else {
    throw new Exception("Not exists function $act() in class $ctrlClassName");
}

function _to_lower_and_ucfirst ($str) {
    return ucfirst(strtolower($str));
}